/*
 * This file is part of Super Luigi Bros.
 * Super Luigi Bros is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Super Luigi Bros is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Super Luigi Bros.  If not, see <http://www.gnu.org/licenses/>.
 */

package luigibros.data.zip.dialog;

import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JTextField;

import luigibros.data.zip.dialog.AboutDialog;

/** This class creates a dialog/window that asks 
 *  for a file name. It should do something with 
 *  the data.xml.level and the zip files. 
 *  However, I am not sure how to do that...
 *  or exactly what I NEED to do with it...
 *  So right now, this just creates a dialog. 
 *  Oh, and the menu bar is there, but it will 
 *  not display.
 *  @author hungryarthi
 */

public class ZipDialog {
	private String fileName;
	private JPanel connectionPanel;
	private JTextField  fileNameField;
	private JFrame window;
	
	/** The constructor:
	 *  Receives the window that the dialog is displayed on - if no window, receives null.
	 *  @param - JFrame wndow
	 *  @author - hungryarthi
	 */
	public ZipDialog(JFrame wndow) {		
		this.window = wndow;
		createDialog();
	}
	
	/** Creates the dialog (panels to place on new small window)
	 *  @return - null
	 *  @author - hungryarthi
	 */
	private void createDialog() {
		//create menubar
		createMenuBar();
		
		//create the labels and text fields.
		JLabel	fileNameLabel = new JLabel("File name:  ", JLabel.LEFT);
		fileNameField = new JTextField("");
		fileNameField.setSize(10, 100);
		connectionPanel = new JPanel(false);
		connectionPanel.setLayout((LayoutManager) new BoxLayout (connectionPanel, BoxLayout.Y_AXIS));

		JPanel namePanel = new JPanel(false);
		namePanel.setLayout(new GridLayout(0, 1));
		namePanel.add(fileNameLabel);
		
		JPanel fieldPanel = new JPanel(false);
		fieldPanel.setLayout(new GridLayout(0,1));
		fieldPanel.add(fileNameField);
		connectionPanel.add(namePanel);
		connectionPanel.add(fieldPanel);
	}
	/** Creates the menubar on the window - but will not display
	 *  @return - null
	 *  @author - hungryarthi
	 */
	private void createMenuBar() {
        JMenuBar menubar = new JMenuBar();

        JMenu file = new JMenu("File");
        file.setMnemonic(KeyEvent.VK_F);
        
        JMenuItem exit = new JMenuItem("Exit");
        file.add(exit);

        JMenu help = new JMenu("Help");
        help.setMnemonic(KeyEvent.VK_H);

        JMenuItem about = new JMenuItem("About");
        help.add(about);

        about.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                AboutDialog ad = new AboutDialog();
                ad.setVisible(true);
            }
        });
        
        /*exit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {
                exitGame();
            	//AboutDialog ad = new AboutDialog();
                //ad.setVisible(true);
            }
        });
        */

        menubar.add(file);
        menubar.add(help);
        window.setJMenuBar(menubar);
	}
	
	//model dialog to get file name
	private static final String[] ConnectOptionNames = { "Continue", "Cancel"};
	private static final String ConnectTitle = "Open Zip File";
	
	/** Displays the window with buttons
	 *  @return - null
	 *  @author - hungryarthi
	 */
	public void display () {
		//Continue or Quit
		if(JOptionPane.showOptionDialog(window, connectionPanel, ConnectTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, ConnectOptionNames, ConnectOptionNames[0]) != 0)
			System.exit(0);
		fileName = fileNameField.getText();
	}
	
	/** returns the filename that has been inputed and saved
	 *  @return - fileName
	 *  @author - hungryarthi
	 */
	public String getFileName(){
		return fileName;
	}
	
/*	public static void main(String[] args){
		new ZipDialog(new JFrame()).display();
	}
*/
}